<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../js/vue.js"></script>
    <style>
        .tip-box{
            position: fixed;
            top: 0px;
            left: 50%;
            transform: translate(-50%,-100%);
            opacity:0;
            background-color: #1a17176b;
            color: white;
            padding: 10px 20px;
            border-radius: 20px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            animation-name:showTip;
            animation-duration:3s;
        }
        @keyframes showTip{
            0%{
                transform:translate(-50%,-100%);
                opacity:0;
            }
            20%{
                transform:translate(-50%,50%);
                opacity:1;
            }
            80%{
                transform:translate(-50%,50%);
                opacity:1;
            }
            100%{
                transform:translate(-50%,-100%);
                opacity:0;
            }
        }
    </style>
</head>
<body>
    <input type="button" value="打开消息提示窗口" onclick="showTip()">
    <input type="button" value="打开消息提示窗口1" onclick="showTip(5)">
</body>
<script>
    var Tip=Vue.extend({
        template:`<div class="tip-box" :style="'animation-duration:'+time+'s;'">{{msg}}</div>`,
        data:function(){
            return {
                msg:"翩若惊鸿，婉若游龙!",
                time:3
            }
        }
    })
    function showTip(time=3){
        var tip=new Tip();
        tip.time=time;
        tip.$mount();
        // console.log(tip.$el);
        document.body.appendChild(tip.$el);
        setTimeout(function(){
            document.body.removeChild(tip.$el);
            tip.$destroy();
        },time*1000);
    }
</script>
</html>